# coding=utf-8
# 全世界最帅的帅哥
from ysgg1_club_auth.comment.utils.decrypt_util import decrypt
from ysgg1_club_auth.comment.utils.decrypt_util import PRIVATE_KEY_PATH
from pathlib import Path
from datetime import timedelta

utils_path = Path(PRIVATE_KEY_PATH).parent.absolute()


class AuthConfig:
    HOSTNAME = '121.40.187.211'
    PORT = '3306'
    DATABASE = 'ysgg1_club'
    USERNAME = 'root'
    ENCRYPTED_DATA = utils_path / 'encrypted_data.bin'
    ENCRYPTED_MAIL_DATA = utils_path / 'encrypted_mail_data.bin'
    # 密码加密
    DB_URI = "mysql+pymysql://{0}:{1}@{2}:{3}/{4}?charset=utf8mb4".format(USERNAME, decrypt(ENCRYPTED_DATA), HOSTNAME,
                                                                          PORT, DATABASE)
    DEBUG = True
    SQLALCHEMY_ECHO = True
    SQLALCHEMY_DATABASE_URI = DB_URI
    # 不需要做数据追踪
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # SECRET_KEY
    SECRET_KEY = "55SPIHI49tNNlrJGivQm"
    # 日志的配置
    LOGGING_LEVEL = "INFO"
    LOGGING_FILE_DIR = Path(__file__).parent.parent / "logs"
    LOGGING_FILE_MAX_BYTES = 300 * 1024 * 1024
    LOGGING_BACKUP = 10

    # JWT配置
    JWT_TOKEN_LOCATION = ["headers", "cookies", "json"]
    JWT_SECRET_KEY = '0c22522f23fd61c8a677bf8f5b073442'
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=1)
    JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)

    # 邮箱配置
    MAIL_SERVER = "smtp.qq.com"
    MAIL_USE_SSL = True
    MAIL_PORT = 465
    MAIL_USERNAME = "1115132733@qq.com"
    MAIL_PASSWORD = decrypt(ENCRYPTED_MAIL_DATA)
    MAIL_DEFAULT_SENDER = "1115132733@qq.com"

    # 采用Redis保存数据，默认是内存，需要安装flask-redis
    RATELIMIT_STORAGE_URL = 'redis://192.168.136.3:6379/4'
    # 限制策略：移动窗口：时间窗口会自动变化
    RATELIMIT_STRATEGY = 'moving-window'
    # redis数据库的连接地址，使用数据库5来存放缓存数据包括短信验证码
    REDIS_URL = 'redis://@192.168.136.3:6379/5'

    AVATAR_DIR = "E:\\financial\\financial\\static\\avatar"
